<template>
  <div id="topSearch">
    <div class="search-box">
      <el-form :inline="true" :model="formInline" ref="ruleForm">
        <el-form-item label="手机号" prop="phone">
          <el-input
            clearable
            maxlength="30"
            placeholder="请输入手机号"
            v-model.trim="formInline.phone"
          ></el-input>
        </el-form-item>
        <el-form-item label="大鹏号" prop="dpAccount">
          <el-input
            clearable
            maxlength="30"
            placeholder="请输入大鹏号"
            v-model.trim="formInline.dpAccount"
          ></el-input>
        </el-form-item>
        <el-form-item label="快递号" prop="courierNumber">
          <el-input
            clearable
            maxlength="30"
            placeholder="请输入快递号"
            v-model="formInline.courierNumber"
          ></el-input>
        </el-form-item>
        <el-form-item label="订单时间" prop="orderTime">
          <el-date-picker
            size="small"
            v-model="formInline.orderTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="商品名称" prop="awardName">
          <el-input
            clearable
            maxlength="30"
            placeholder="请输入商品名称"
            v-model="formInline.awardName"
          ></el-input>
        </el-form-item>
        <el-form-item label="商品类型" prop="awardType">
          <el-select
            clearable
            size="small"
            placeholder="全部"
            v-model="formInline.awardTypeList"
          >
            <el-option
              v-for="item in awardTypeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="商品发放状态" prop="giveAwardState">
          <el-select
            clearable
            size="small"
            placeholder="全部"
            v-model="formInline.giveAwardState"
          >
            <el-option
              v-for="item in giveAwardStateList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="活动类型" prop="activityType">
          <el-select
            clearable
            size="small"
            placeholder="请选择活动类型"
            v-model="formInline.activityType"
          >
            <el-option
              v-for="item in activityTypeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="活动名称" prop="activityName">
          <el-input
            clearable
            maxlength="30"
            placeholder="请输入活动名称"
            v-model="formInline.activityName"
          ></el-input>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button type="success" icon="el-icon-search" @click="toSearch">
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  data() {
    return {
      formInline: {
        orderTime: [],
        phone: '',
        dpAccount: '',
        // 订单号
        courierNumber: '',
        orderTimeStart: '',
        orderTimeEnd: '',
        awardName: '',
        // 商品类型 奖品类型:[ENTITY,VIRTUAL]
        awardType: '',
        // 商品发放状态,可用值:YES,NO
        giveAwardState: '',
        // 活动类型,[PRAISE,RECOMMEND]
        activityType: '',
        activityName: '',
        pageNum: 1,
        pageSize: 10
      },
      activeList: [],
      statusOptions: [],
      awardTypeList: [],
      activityTypeList: [],
      giveAwardStateList: [
        {
          value: 'YES',
          label: '已发奖'
        },
        {
          value: 'NO',
          label: '未发奖'
        }
      ]
    }
  },
  watch: {
    'formInline.orderTime': {
      handler(val) {
        this.formInline.startTime = val && val.length ? val[0] : ''
        this.formInline.endTime = val && val.length ? val[1] : ''
      },
      deep: true
    }
  },
  mounted() {
    this.getTopSearch()
  },
  methods: {
    // 获取顶部搜索条件
    async getTopSearch() {
      // 获取活动类型
      this.activityTypeList = await sysNormalDisable('activity_order_types')
      // 获取奖品类型
      this.awardTypeList = await sysNormalDisable('activity_order_order_types')
    },
    /* 搜索 */
    toSearch() {
      const obj = Object.assign({}, this.formInline)
      delete obj.orderTime
      this.$emit('toSearch', obj)
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
      this.$parent.searchList()
    }
  }
}
</script>
<style lang="less" scoped></style>
